package com.teamwork;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class jsxxzs {
    public static void displayTeacherData() {
        try {
            // 加载数据库驱动
            Class.forName("com.mysql.cj.jdbc.Driver");

            // 连接数据库
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/studentexam", "root", "123456");

            // 创建Statement对象
            Statement statement = connection.createStatement();

            // 执行SQL查询
            ResultSet resultSet = statement.executeQuery("SELECT * FROM teacher");

            // 输出学生信息
            while (resultSet.next()) {
                System.out.println("教师ID： " + resultSet.getInt("TId") + ", 姓名： " + resultSet.getString("Tname") + ", 密码： " + resultSet.getString("Tpwd") + ", 真实姓名： " + resultSet.getString("TRname") + ", 班级编号： " + resultSet.getString("CLId"));
            }

            // 关闭资源
            resultSet.close();
            statement.close();
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
